﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebSite_that_use_Wizard.NET
{
    public partial class Sessions : System.Web.UI.Page
    {
        private Wizard.Asp.AspEngine mWizardEngine;
        private Wizard.IDataStoreContext mDataStoreContext;
                
        protected void Page_Load(object sender, EventArgs e)
        {
            mWizardEngine = (Wizard.Asp.AspEngine)Application["WizardEngine"];
            mDataStoreContext = mWizardEngine.DataStore.GetNewContext();

            var wizardSession = mDataStoreContext.GetSession(this.Session.SessionID);
            lblCurrentSession.Text = wizardSession.SessionId.ToString();
        }

        public Wizard.Source.ISession[] GetSessions()
        {
            if (mDataStoreContext == null)
            {
                if (Session == null) return null;
                mWizardEngine = (Wizard.Asp.AspEngine)Session["WizardEngine"];
                mDataStoreContext = mWizardEngine.DataStore.GetNewContext();
            }
            return mDataStoreContext.GetSessions();
        }

        protected void ViewSession_Click(object sender, EventArgs e)
        {
            string sessionId = ((LinkButton)sender).CommandArgument;
            Response.Redirect("Session.aspx?id=" + sessionId);
        }

        protected void DeleteSession_Click(object sender, EventArgs e)
        {
            string sessionId = ((LinkButton)sender).CommandArgument;
            mDataStoreContext.DeleteSession(int.Parse(sessionId));

        }

    }
}
